﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using br.com.SistemaChamados.Model;
using br.com.SistemaChamados;
using br.com.SistemaChamados.Enum;

namespace br.com.SistemaChamados.DAO
{
    public class AnnexDAO
    {
        private static string SQL_INSERT_ANNEX = " INSERT INTO TBL_ANNEX (TBL_ANNEXDESCRIPTION, TBL_CALLID) VALUES (@annexdescription, @callid) ";
        
        public EnumGenericState InsertAnnex(Annex annex)
        {

            EnumGenericState resultAnnex = EnumGenericState.GENERIC_STATE_UNKNOW;
            IDbConnection conn = null;
            IDbCommand command = null;

            try
            {
                conn = Mapped.Connection();
                command = Mapped.Command(SQL_INSERT_ANNEX, conn);
                command.Parameters.Add(Mapped.Parameter("@annexdescription", annex.Description));
                command.Parameters.Add(Mapped.Parameter("@callid", annex.Call.Id));
                command.ExecuteNonQuery();
                resultAnnex = EnumGenericState.GENERIC_STATE_SUCCESS;
            }
            catch (Exception ex)
            {
                resultAnnex = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            finally
            {
                if (conn != null) conn.Close();
            }

            return resultAnnex;

        }
        
        public AnnexDAO()
        {
            //
            // TODO: Add constructor logic here
            //
        }
    }
}